Skip to content

[1/3 messagequeue] Shard MySQL queues by tenant identity - #694

Merged
behinddwalls merged 2 commits into
mainfrom
preetam/mq-tenant-platform
Sep 10, 2026
Merged

[1/3 messagequeue] Shard MySQL queues by tenant identity#694
behinddwalls merged 2 commits into
mainfrom
preetam/mq-tenant-platform

Conversation

@behinddwalls

@behinddwalls behinddwalls commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Why?

Vitess needs a stable vindex that is not the Kafka-style partition key. Isolation has to be an explicit tenant column, with identity carried on publish and consume so two tenants sharing a partition key cannot collide.

What?

  • Prefix every queue table and store query with tenant; set queue_offsets PK to (tenant, topic, partition_key, consumer_group).
  • Use typed (tenant, partitionKey) identities in consumers, gates, and MySQL workers; stop workers when lease discovery cannot confirm ownership.
  • Require tenant on publish.Message and validate payload queue against message tenant in pipeline controllers (the publish signature change is not compilable without those call sites).
  • Add ParseRequiredTenants and wire Stovepipe ingest to the configured tenant list so NewIngestController still builds.
  • Require tenant xor all-tenants on MQ admin list commands; message inspect/delete/requeue take the full (tenant, topic, partition, id) identity.
  • Comment ascii/ascii_bin vs utf8mb4/utf8mb4_bin on every queue table, with the full encoding note on queue_messages.

Test Plan

go test on mysql, publish, consumer, messagequeue identity, service/messagequeue, and start controller

Rebased onto current main after RFC #693 merged.

Stack

  • #693 RFC: per-tenant sharding for the MySQL message queue (merged)
  • #694 Shard MySQL queues by tenant identity
  • #695 Wire MQ_TENANTS through services and tests
  • #696 Add Vitess vschema and two-shard vtcombo suite

@behinddwalls
behinddwalls force-pushed the preetam/mq-tenant-platform branch 2 times, most recently from 6ac133e to 58adda2 Compare September 8, 2026 06:06
@behinddwalls
behinddwalls marked this pull request as ready for review September 10, 2026 16:30
@behinddwalls
behinddwalls requested review from a team and sbalabanov as code owners September 10, 2026 16:30
Base automatically changed from preetam/mq-tenant-rfc to main September 10, 2026 16:38
behinddwalls and others added 2 commits September 10, 2026 11:55
## Summary

### Why?

Vitess needs a stable vindex that is not the Kafka-style partition key. Isolation has to be an explicit tenant column, with identity carried on publish and consume so two tenants sharing a partition key cannot collide.

### What?

- Prefix every queue table and store query with tenant; set queue_offsets PK to (tenant, topic, partition_key, consumer_group).
- Use typed (tenant, partitionKey) identities in consumers, gates, and MySQL workers; stop workers when lease discovery cannot confirm ownership.
- Require tenant on publish.Message and validate payload queue against message tenant in pipeline controllers (the publish signature change is not compilable without those call sites).
- Add ParseRequiredTenants and wire Stovepipe ingest to the configured tenant list so NewIngestController still builds.
- Require tenant xor all-tenants on MQ admin list commands; message inspect/delete/requeue take the full (tenant, topic, partition, id) identity.

## Test Plan

✅ `go test` on mysql, publish, consumer, messagequeue identity, service/messagequeue, and start controller

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	stovepipe/controller/dlq/dlq_test.go

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# interactive rebase in progress; onto 39d91a4
# Last command done (1 command done):
#    pick b436d8f # [2/4 messagequeue] Shard MySQL queues by tenant identity
# Next command to do (1 remaining command):
#    pick 58adda2 # docs(messagequeue): comment ascii vs utf8mb4 column encodings in schema
# You are currently rebasing branch 'preetam/mq-tenant-platform' on '39d91a44'.
#
# Changes to be committed:
#	modified:   platform/base/messagequeue/BUILD.bazel
#	new file:   platform/base/messagequeue/identity.go
#	new file:   platform/base/messagequeue/identity_test.go
#	modified:   platform/base/messagequeue/message.go
#	new file:   platform/base/messagequeue/partition.go
#	modified:   platform/consumer/consumer.go
#	modified:   platform/consumer/consumer_test.go
#	modified:   platform/extension/consumergate/BUILD.bazel
#	modified:   platform/extension/consumergate/consumergate.go
#	modified:   platform/extension/consumergate/file/BUILD.bazel
#	modified:   platform/extension/consumergate/file/store.go
#	modified:   platform/extension/consumergate/file/store_test.go
#	modified:   platform/extension/consumergate/noop/BUILD.bazel
#	modified:   platform/extension/consumergate/noop/gate_test.go
#	modified:   platform/extension/messagequeue/mysql/BUILD.bazel
#	modified:   platform/extension/messagequeue/mysql/constants.go
#	modified:   platform/extension/messagequeue/mysql/ctl/BUILD.bazel
#	modified:   platform/extension/messagequeue/mysql/ctl/README.md
#	modified:   platform/extension/messagequeue/mysql/ctl/commands.go
#	new file:   platform/extension/messagequeue/mysql/ctl/commands_test.go
#	modified:   platform/extension/messagequeue/mysql/ctl/lib/admin.go
#	modified:   platform/extension/messagequeue/mysql/ctl/lib/admin_test.go
#	modified:   platform/extension/messagequeue/mysql/delivery_state_store.go
#	modified:   platform/extension/messagequeue/mysql/delivery_state_store_test.go
#	new file:   platform/extension/messagequeue/mysql/identifier.go
#	modified:   platform/extension/messagequeue/mysql/message_store.go
#	modified:   platform/extension/messagequeue/mysql/message_store_test.go
#	modified:   platform/extension/messagequeue/mysql/mock_stores.go
#	modified:   platform/extension/messagequeue/mysql/offset_store.go
#	modified:   platform/extension/messagequeue/mysql/offset_store_test.go
#	modified:   platform/extension/messagequeue/mysql/partition_lease_store.go
#	modified:   platform/extension/messagequeue/mysql/partition_lease_store_test.go
#	modified:   platform/extension/messagequeue/mysql/publisher.go
#	modified:   platform/extension/messagequeue/mysql/publisher_test.go
#	modified:   platform/extension/messagequeue/mysql/schema/queue_delivery_state.sql
#	modified:   platform/extension/messagequeue/mysql/schema/queue_messages.sql
#	modified:   platform/extension/messagequeue/mysql/schema/queue_offsets.sql
#	modified:   platform/extension/messagequeue/mysql/schema/queue_partition_leases.sql
#	modified:   platform/extension/messagequeue/mysql/schema/queue_subscriber_heartbeats.sql
#	modified:   platform/extension/messagequeue/mysql/sql.go
#	modified:   platform/extension/messagequeue/mysql/sql_test.go
#	modified:   platform/extension/messagequeue/mysql/stores.go
#	modified:   platform/extension/messagequeue/mysql/subscriber.go
#	modified:   platform/extension/messagequeue/mysql/subscriber_heartbeat_store.go
#	modified:   platform/extension/messagequeue/mysql/subscriber_heartbeat_store_test.go
#	modified:   platform/extension/messagequeue/mysql/subscriber_test.go
#	modified:   platform/hook/publisher.go
#	modified:   platform/hook/publisher_test.go
#	modified:   platform/publish/publish.go
#	modified:   platform/publish/publish_test.go
#	modified:   runway/controller/dlq/BUILD.bazel
#	modified:   runway/controller/dlq/dlq.go
#	modified:   runway/controller/dlq/dlq_test.go
#	modified:   runway/controller/merge/BUILD.bazel
#	modified:   runway/controller/merge/merge.go
#	modified:   runway/controller/merge/merge_test.go
#	modified:   runway/controller/mergeconflictcheck/BUILD.bazel
#	modified:   runway/controller/mergeconflictcheck/mergeconflictcheck.go
#	modified:   runway/controller/mergeconflictcheck/mergeconflictcheck_test.go
#	new file:   service/messagequeue/BUILD.bazel
#	new file:   service/messagequeue/tenant.go
#	new file:   service/messagequeue/tenant_test.go
#	modified:   service/stovepipe/server/BUILD.bazel
#	modified:   service/stovepipe/server/main.go
#	modified:   stovepipe/controller/BUILD.bazel
#	modified:   stovepipe/controller/build/BUILD.bazel
#	modified:   stovepipe/controller/build/build.go
#	modified:   stovepipe/controller/build/build_test.go
#	modified:   stovepipe/controller/buildsignal/BUILD.bazel
#	modified:   stovepipe/controller/buildsignal/buildsignal.go
#	modified:   stovepipe/controller/buildsignal/buildsignal_test.go
#	modified:   stovepipe/controller/dlq/BUILD.bazel
#	modified:   stovepipe/controller/dlq/build.go
#	modified:   stovepipe/controller/dlq/build_test.go
#	modified:   stovepipe/controller/dlq/buildsignal.go
#	modified:   stovepipe/controller/dlq/buildsignal_test.go
#	modified:   stovepipe/controller/dlq/dlq_test.go
#	modified:   stovepipe/controller/dlq/request.go
#	modified:   stovepipe/controller/ingest.go
#	modified:   stovepipe/controller/ingest_test.go
#	modified:   stovepipe/controller/process/BUILD.bazel
#	modified:   stovepipe/controller/process/process.go
#	modified:   stovepipe/controller/process/process_test.go
#	modified:   stovepipe/controller/record/BUILD.bazel
#	modified:   stovepipe/controller/record/record.go
#	modified:   stovepipe/controller/record/record_test.go
#	modified:   submitqueue/core/request/log.go
#	modified:   submitqueue/core/request/log_test.go
#	modified:   submitqueue/core/request/terminate_test.go
#	modified:   submitqueue/gateway/controller/cancel.go
#	modified:   submitqueue/gateway/controller/cancel_test.go
#	modified:   submitqueue/gateway/controller/land.go
#	modified:   submitqueue/gateway/controller/land_test.go
#	modified:   submitqueue/gateway/controller/log/BUILD.bazel
#	modified:   submitqueue/gateway/controller/log/log.go
#	modified:   submitqueue/gateway/controller/log/log_test.go
#	modified:   submitqueue/orchestrator/controller/batch/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/batch/batch.go
#	modified:   submitqueue/orchestrator/controller/batch/batch_test.go
#	modified:   submitqueue/orchestrator/controller/build/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/build/build.go
#	modified:   submitqueue/orchestrator/controller/build/build_test.go
#	modified:   submitqueue/orchestrator/controller/buildsignal/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/buildsignal/buildsignal.go
#	modified:   submitqueue/orchestrator/controller/buildsignal/buildsignal_test.go
#	modified:   submitqueue/orchestrator/controller/cancel/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/cancel/cancel.go
#	modified:   submitqueue/orchestrator/controller/cancel/cancel_test.go
#	modified:   submitqueue/orchestrator/controller/conclude/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/conclude/conclude.go
#	modified:   submitqueue/orchestrator/controller/conclude/conclude_test.go
#	modified:   submitqueue/orchestrator/controller/dependencyanalysis/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/dependencyanalysis/dependencyanalysis.go
#	modified:   submitqueue/orchestrator/controller/dependencyanalysis/dependencyanalysis_test.go
#	modified:   submitqueue/orchestrator/controller/dlq/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/dlq/batch.go
#	modified:   submitqueue/orchestrator/controller/dlq/batch_test.go
#	modified:   submitqueue/orchestrator/controller/dlq/buildsignal.go
#	modified:   submitqueue/orchestrator/controller/dlq/buildsignal_test.go
#	modified:   submitqueue/orchestrator/controller/dlq/dlq_test.go
#	modified:   submitqueue/orchestrator/controller/dlq/mergeconflictsignal.go
#	modified:   submitqueue/orchestrator/controller/dlq/mergeconflictsignal_test.go
#	modified:   submitqueue/orchestrator/controller/dlq/mergesignal.go
#	modified:   submitqueue/orchestrator/controller/dlq/mergesignal_test.go
#	modified:   submitqueue/orchestrator/controller/dlq/publisher_test.go
#	modified:   submitqueue/orchestrator/controller/dlq/request.go
#	modified:   submitqueue/orchestrator/controller/dlq/request_test.go
#	modified:   submitqueue/orchestrator/controller/dlq/speculate.go
#	modified:   submitqueue/orchestrator/controller/dlq/speculate_test.go
#	modified:   submitqueue/orchestrator/controller/merge/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/merge/merge.go
#	modified:   submitqueue/orchestrator/controller/merge/merge_test.go
#	modified:   submitqueue/orchestrator/controller/mergeconflictsignal/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/mergeconflictsignal/mergeconflictsignal.go
#	modified:   submitqueue/orchestrator/controller/mergeconflictsignal/mergeconflictsignal_test.go
#	modified:   submitqueue/orchestrator/controller/mergesignal/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/mergesignal/mergesignal.go
#	modified:   submitqueue/orchestrator/controller/mergesignal/mergesignal_test.go
#	modified:   submitqueue/orchestrator/controller/speculate/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/speculate/run_test.go
#	modified:   submitqueue/orchestrator/controller/speculate/speculate.go
#	modified:   submitqueue/orchestrator/controller/speculate/speculate_test.go
#	modified:   submitqueue/orchestrator/controller/start/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/start/start.go
#	modified:   submitqueue/orchestrator/controller/start/start_test.go
#	modified:   submitqueue/orchestrator/controller/validate/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/validate/validate.go
#	modified:   submitqueue/orchestrator/controller/validate/validate_test.go
#	modified:   test/e2e/submitqueue/BUILD.bazel
#	modified:   test/e2e/submitqueue/harness_test.go
#	modified:   test/e2e/submitqueue/suite_test.go
#	modified:   test/integration/extension/messagequeue/mysql/BUILD.bazel
#	modified:   test/integration/extension/messagequeue/mysql/queue_test.go
#	new file:   test/integration/extension/messagequeue/mysql/tenant_isolation_test.go
#	modified:   tool/linter/queueshard/main.go
#	modified:   tool/linter/queueshard/main_test.go
#
## Summary

### Why?

The CREATE TABLE statements encode two different VARCHAR(255) contracts. A reader opening the SQL should see the byte vs character limits, binary collations, and why tenant stays ASCII.

### What?

- Comment ascii/ascii_bin vs utf8mb4/utf8mb4_bin on every queue table, with the full encoding note on queue_messages.

Co-authored-by: Cursor <cursoragent@cursor.com>
@behinddwalls
behinddwalls force-pushed the preetam/mq-tenant-platform branch from 58adda2 to 95ba176 Compare September 10, 2026 18:57
@behinddwalls behinddwalls changed the title [2/4 messagequeue] Shard MySQL queues by tenant identity [1/3 messagequeue] Shard MySQL queues by tenant identity Sep 10, 2026
@behinddwalls
behinddwalls merged commit bb91254 into main Sep 10, 2026
9 of 14 checks passed
@behinddwalls
behinddwalls deleted the preetam/mq-tenant-platform branch September 10, 2026 19:48
behinddwalls added a commit that referenced this pull request Sep 10, 2026
## Summary

### Why?

The MySQL subscriber only discovers partitions for configured tenants.
Service processes and compose stacks must pass the same list they
already use as queue names, or Subscribe fails at startup and tests talk
to an unsharded process.

### What?

- Parse MQ_TENANTS in gateway, orchestrator, and runway wiring and
reject configs whose queue names do not match.
- Set MQ_TENANTS in service compose files, e2e harnesses, and
SubmitQueue integration suites.

## Test Plan

✅ `go test` TestValidateConfiguredQueueTenants,
TestValidateProfileQueueTenants, TestValidateMergeQueueTenants, and
service/messagequeue

Rebased onto current `main` after #694 merged.

## Stack

- ~~[#693](#693) RFC: per-tenant
sharding for the MySQL message queue~~ (merged)
- ~~[#694](#694) Shard MySQL
queues by tenant identity~~ (merged)
- [#695](#695) Wire MQ_TENANTS
through services and tests
- [#696](#696) Add Vitess
vschema and two-shard vtcombo suite

Co-authored-by: Cursor <cursoragent@cursor.com>
behinddwalls added a commit that referenced this pull request Sep 10, 2026
## Summary

### Why?

The MySQL subscriber only discovers partitions for configured tenants.
Service processes and compose stacks must pass the same list they
already use as queue names, or Subscribe fails at startup and tests talk
to an unsharded process.

### What?

- Parse MQ_TENANTS in gateway, orchestrator, and runway wiring and
reject configs whose queue names do not match.
- Set MQ_TENANTS in service compose files, e2e harnesses, and
SubmitQueue integration suites.

## Test Plan

✅ `go test` TestValidateConfiguredQueueTenants,
TestValidateProfileQueueTenants, TestValidateMergeQueueTenants, and
service/messagequeue

Rebased onto current `main` after #694 merged.

## Stack

- ~~[#693](#693) RFC: per-tenant
sharding for the MySQL message queue~~ (merged)
- ~~[#694](#694) Shard MySQL
queues by tenant identity~~ (merged)
- [#695](#695) Wire MQ_TENANTS
through services and tests
- [#696](#696) Add Vitess
vschema and two-shard vtcombo suite

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants